<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div class="btns">
      <button data-path="news">新闻</button>
      <button data-path="play">娱乐</button>
      <button data-path="game">游戏</button>
    </div>
    <div class="container"></div>
  </body>
  <script>
    const oContainer = document.querySelector(".container");
    const routes = [
      { path: "/news", content: "我是新闻模块" },
      { path: "/play", content: "我是娱乐模块" },
      { path: "/game", content: "我是游戏模块" },
    ];
    const oBtns = document.querySelectorAll(".btns button");
    for (var i = 0; i < oBtns.length; i++) {
      oBtns[i].onclick = function () {
        history.pushState(null, null, this.dataset.path);

        routes.forEach((item) => {
          if (item.path.slice(1) === this.dataset.path) {
            oContainer.textContent = item.content;
          }
        });
      };
    }
  </script>
</html>
